package com.yikang.real.activity;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.CheckedChange;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import com.yikang.real.R;
import com.yikang.real.application.BaseActivity;
import com.yikang.real.fragment.ForrentFragments_;
import com.yikang.real.fragment.NewHouseFragment;
import com.yikang.real.fragment.OldHouseFragment_;
import com.yikang.real.fragment.PersonCentrol;
import com.yikang.real.fragment.PersonCentrol_;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.RadioButton;

@EActivity(R.layout.activity_main)
public class CheckedActivity extends BaseActivity {

	@ViewById(R.id.radio_button0)
	public RadioButton mTab1;
	@ViewById(R.id.radio_button1)
	public RadioButton mTab2;
	@ViewById(R.id.radio_button2)
	public RadioButton mTab3;
	@ViewById(R.id.radio_button3)
	public RadioButton mTab4;
	@ViewById(R.id.pager)
	public ViewPager pager;

	public CompoundButton currentButtonView;

	Fragment[] fragments ;
	MyAdapter mAdapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mAdapter = new MyAdapter(getSupportFragmentManager());
	}

	@AfterViews
	public void afterView(){
		pager.setAdapter(mAdapter);
		mTab1.performClick();
	}
	
	@CheckedChange(value={R.id.radio_button0,R.id.radio_button1,R.id.radio_button2,R.id.radio_button3})
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (isChecked) {
		      switch (buttonView.getId()) {
	            case R.id.radio_button1:
	             	pager.setCurrentItem(1);
	            	break;
	            case R.id.radio_button2:
	             	pager.setCurrentItem(2);
	            	break;
	            case R.id.radio_button3:
	             	pager.setCurrentItem(3);
	            	break;
	            case R.id.radio_button0:
	            default:
	            	pager.setCurrentItem(0);
	            	break;
	            }
		
		}
	}

	 public static class MyAdapter extends FragmentPagerAdapter {
	        public MyAdapter(FragmentManager fm) {
	            super(fm);
	        }

	        @Override
	        public int getCount() {
	            return 4;
	        }

	        @Override
	        public Fragment getItem(int position) {
	            switch (position) {
	            case 0:
	            	return NewHouseFragment.instantiation(2);
	            case 1:
	                return NewHouseFragment.instantiation(0);
	            case 2:
	                return NewHouseFragment.instantiation(1);
	            case 3:
	            default:
	                return new PersonCentrol_();
	            }
	        }

			@Override
			public void destroyItem(ViewGroup container, int position,
					Object object) {
				// TODO Auto-generated method stub
			}
	        
	    }

	
	@Override
	protected void initData() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void initListeners() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void initActionBar() {
		// TODO Auto-generated method stub
		
	}
}
